<template>
	<view class="content">
	 
		<!-- village -->
		<view class="village-box">
			<view class="village-item" v-for="(item,index) in villageList" :key="index">
				<view class="village-item-left">
					<view class="shuxian"></view>
					<view class="adress-box">
						<view class="adress">{{item.id}}{{name}}</view>
					</view>
				</view>
				<view class="village-item-right" @click="pushMap(item.id)">
					<view class="huhao">查看</view>
				</view>
			</view>
			<view class="nomodel" v-if="villageList.length==0">
				<u-empty  text="暂无内容"  mode="list"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	 
	export default { 
		data() {
			return {
				username: '',
				password: '',
				// array: ['安装工','检测工','维修工'],
				index: 0,
				userinfo:{},
				value:'',  //搜索关键词
				installList:[],  //安装列表
				dosearch:false,
				showAcount:false,
				page:1,
				villageList:[],
				active:0,
				token:'',
				totwn: 0,
				village: '',
				id: '',
				ids: '',
				name: ''
			};
		},
		onLoad(option) {
			this.id = option.id
			this.ids = option.ids
			this.name = option.name
			console.log(this.name);
		},
		onShow() {
			uni.getStorage({
				key: 'token'
			}).then(da => {
				this.token = da[1].data
			})
			setTimeout(() => {
				this.getInstallDetail()
				this.getMap()
			},10)
		},
		//下拉刷新
		// onPullDownRefresh(){
		// 	this.page=1
		// 	 setTimeout(function() {
		// 	 	uni.stopPullDownRefresh();
		// 	 }, 500);
		// 	// this.getInstallDetail()
		// },
		// onReachBottom() {
		// 	this.page++
		// 	if(this.page >= this.totwn) {
		// 		uni.showToast({
		// 			title: '已经到底了',
		// 			icon: 'none'
		// 		})
		// 		return
		// 	}
		// 	this.getInstallDetail()
		// },
		methods: {
			// 获取安装数据
			getInstallDetail () {
				let that = this
				that.$request.request({
					url: 'equipment/equipment_list',
					method: 'POST',
					data: {
						token: that.token,
						village: that.id,
						type:that.ids
					}
				}).then(res => {
					if(res.data.code == 1) {
						that.villageList = res.data.data
						// that.totwn = res.data.data.page_count
					}
				})
			 },
			 getMap() {
				 let that = this
				 uni.getLocation({
				     type: 'wgs84',
					 geocode:true,
				     success: function (res) {
						 that.long = res.longitude
						 that.lat = res.latitude
				     }
				 });
			 },
			 pushMap(id) {
				 let that = this
				 let type = ''
				 if(that.name == '阀门') {
					 type = 1
				 }
				 if(that.name == '调压箱') {
				 	type = 2
				 }
				 that.$request.request({
					 url: 'equipment/position_update',
					 method: 'POST',
					 data: {
						 token: that.token,
						 type: type,
						 equipment_id: id,
						 long: that.long,
						 lat: that.lat
					 }
				 }).then(res => {
					if(res.data.code == 1) {
						uni.navigateTo({
							url: '/pagesA/maps/maps?lat=' + that.lat + '&long=' + that.long
						})
					}
				 })
			 },
			 back() {
			 	uni.navigateBack({
			 		delta: 1
			 	})
			 }
		},
		
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #F5F5F5;
		// padding-bottom: 200upx;
		// margin-bottom: 150upx;
	}
	.content{
		padding-bottom: 140upx;
	}
	.header{
		display: flex;
		justify-content:space-between;
		align-items: center;
		padding: 30upx 30upx;
		background-color: #fff;
		.header-left{
			display: flex;
			align-items: center;
			font-size: 32upx;
			font-weight: 500;
			color: #333;
			image{
				width: 24upx;
				height: 24upx;
				margin-right: 20upx;
			}
		}
		.header-right{
			display: flex;
			align-items: center;
			font-size: 24upx;
			color: #333;
			image{
				width: 52upx;
				height: 52upx;
				margin-right: 10upx;
			}
		}
	}
	.test-code:active{
		background: rgba(69, 82, 202, 0.4);
		color: #fff;
	}
	.plac-class{
		font-size: 32upx;
		color: #999;
	}
	// nav
	.nav{
		width: 100%;
		height: 80upx;
		background-color: #fff;
		.nav-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 50%;
			margin: 0 auto;
			line-height: 76upx;
			span{
				padding: 0 10upx;
				font-size: 32upx;
				color: #333;
				border-bottom: 4upx solid transparent;
			}
			.current{
				color: #003690;
				border-bottom: 4upx solid #003690;
			}
		}
	}
	// danger
	.village-item{
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		width: 690upx;
		padding:20upx 30upx;
		background-color: #fff;
		border-radius: 10upx;
		margin: 20upx auto 0;
		box-shadow:0px 3px 4px rgba(0,30,57,0.15);
		.shuxian{
			width: 8upx;
			height: 28upx;
			background-color: #003690;
			border-radius: 8upx;
			margin-right: 20upx;
		}
		.flag{
			position: absolute;
			right: 0;
			top: 0;
			width: 64upx;
			height: 64upx;
		}
		.village-item-left{
			display: flex;
			align-items: center;
			.adress-box{
				display: flex;
				align-items: center;
				position: relative;
				.shuxian{
					width: 8upx;
					height: 28upx;
					background-color: #003690;
					border-radius: 8upx;
					margin-right: 20upx;
				}
				.adress{
					font-size: 32upx;
					color: #333;
				}
				.adressPosini{
					position: absolute;
					top: -10upx;
					right: -30upx;
					width: 44upx;
					height: 32upx;
					background-color: #d10000;
					opacity: 0.56;
					color: #fff;
					border-radius: 20upx;
					text-align: center;
					line-height: 32upx;
					font-size: 24upx;
				}
			}
			.time{
				display: flex;
				align-items: center;
				font-size: 24upx;
				color: #777;
				image{
					width: 28upx;
					height: 28upx;
					margin-right: 10upx;
				}
			}
			
		}
		.village-item-right{
			display: flex;
			align-items: center;
			.huhao{
				width: 100upx;
				height: 48upx;
				border: 2upx solid #003690;
				border-radius: 24upx;
				font-size: 28upx;
				color: #003690;
				margin-right: 30upx;
				text-align: center;
			}
			.huhao1{
				width: 94upx;
				height: 46upx;
				border: 2upx solid #dddddd;
				border-radius: 16upx;
				font-size: 28upx;
				color: #dddddd;
				margin-right: 30upx;
				text-align: center;
			}
		}
	}
</style>
